package com.example.demo.service.redis;

import com.alibaba.dubbo.config.annotation.Service;
import com.cclub.inteface.service.common.redisTools;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

@Component
@Service(version = "1.0.0",interfaceClass = redisTools.class)
public class redisCache implements redisTools{

    @Resource
    private  RedisTemplate<String,Object> redisTemplate;

    @Override
    public Object getCache(String key) {
        return redisTemplate.opsForValue().get(key);
    }

    @Override
    public void setCache(String key, Object value,long timeOut) {
        redisTemplate.opsForValue().set(key,value,timeOut,TimeUnit.SECONDS);
    }

    @Override
    public void delCache(String key) {
        redisTemplate.delete(key);
    }

    @Override
    public void hmSet(String hashKey, String key, Object value) {
        redisTemplate.opsForHash().put(hashKey,key,value);
    }

    @Override
    public Object hmGet(String hashKey, String key) {
        return redisTemplate.opsForHash().get(hashKey,key);
    }

    @Override
    public Long getKeyExpire(String key) {
        return redisTemplate.opsForValue().getOperations().getExpire(key);
    }
}
